{include file="admin@public/header"/}

<link rel="stylesheet" href="/public/static/admin/css/report.css" />
<link rel="stylesheet" href="/public/static/admin/easyui/layui-v2.6.8/css/layui.css">

<style>
	.ui-icon-ellipsis {
		right: 5px;
	}

	#filter-menu .con {
		width: 355px;
	}

	#filter-menu label.tit {
		width: 80px;
	}

	/*.ui-jqgrid tr.jqgrow td {
	white-space: normal !important;
	}
	*/
	.no-query {
		background: url("/public/static/admin/css/img/no_query.png") no-repeat scroll 100px 60px #fff;
		background-position: center;
		border: 1px solid #ddd;
		border-top: none;
		height: 402px;
		margin-right: 0;
	}

	.box-flex {
		overflow: hidden;
		zoom: 1;
	}

	.box-flex .flex {
		float: left;
		width: 33.3%;
	}

	.grid-title {
		font-size: 24px;
		text-align: center;
		clear: none;
	}

	.ui-print .grid-wrap {
		padding: 10px 0 0 30px;
	}

	#conditions-trigger {
		background: url(/public/static/admin/css/img/bg.png) no-repeat;
		border: 0px;
		width: 74px;
		box-shadow: 0px 0px;
	}

	#filter-menu .conditions-trigger>b {
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -8px;
		width: 16px;
		height: 16px;
		background: url(/public/static/admin/css/img/down.png) 2px 5px no-repeat;
	}

	#filter-menu .conditions-trigger>b.act {
		background: url(/public/static/admin/css/img/up.png) 2px 5px no-repeat;
	}

	#filter-menu .btns {
		position: absolute;
		top: 7px;
		right: 0px;
	}

	.layui-form-checkbox[lay-skin=primary] i {
		padding: 0;
	}

	.layui-form-checked[lay-skin=primary] i {
		border-color: #5dc5e7;
		background-color: #5dc5e7;
		color: #fff;
		padding: 0;
	}

	.layui-form-checkbox[lay-skin=primary]:hover i {
		border-color: #5dc5e7;
	}

	.ui-droplist-wrap {
		height: auto;
	}

	#filterItems {
		height: auto;
	}
    .ui-droplist-wrap .list-item:hover{
        background-color: #faffad;
    }
    .ui-print .ui-jqgrid .ui-jqgrid-hdiv, .ui-print .ui-jqgrid .ui-jqgrid-htable th{background: url(/public/static/admin/youshang/css/img/ui-th.png) repeat-x #EEE;}
    #filterItems{margin-right: 0;padding-right: 10px;}
	
	.mod-search{ position:relative; }
	#custom{ position:absolute; top:0; right:0; }
	.ui-jqgrid-bdiv .ui-state-highlight { background: none; }
	#manager li{margin: 8px 0;}
	#manager .ui-label{width: 204px;display: inline-block;line-height: 18px;font-size: 14px;text-align: center;}
	#manager .ui-label-warning:hover{background-color: #FFBA5A;}
	.no-query{border: none;}
	.qtyInsert{margin-left: 8px;font-weight: 100;font-size: 12px;color: #fff;background-color: #B1B1B1;padding: 0 5px;border-radius: 2px;line-height: 19px;height: 20px;display: inline-block; }
	.qtyInsertAfter{margin-right: 8px;font-weight: 100;font-size: 12px;color: #fff;background-color: #23B317;padding: 0 5px;border-radius: 2px;line-height: 19px;height: 20px;display: inline-block;}



</style>

<div class="wrapper">
	<!-- header -->
	<div class="mod-search cf">
		<div class="l  layui-form" id="filter-menu">
			<ul class="ul-inline fix" id="filterItems" style="font-size: 12px;">
				
                <!-- 选择仓库 -->
            	{include file="admin@select/store"/}

				<!-- 选择商品类别 -->
            	{include file="admin@select/goods_category"/}

				<li id="goods" style="display: list-item;">
					<label>商品:</label>
					<span class="mod-choose-input" id="filter-goods">
						<input type="text" class="ui-input" id="goodsAuto" autocomplete="off" placeholder="请输入商品编号或者商品名" style="padding-right: 0;width: 170px;font-size: 12px;">
					</span>
                    
				</li>
                <li id="chkField" style="padding-top: 13px;height: 44px;box-sizing: border-box;">
                    <input type="checkbox" name="box" id="showZero" lay-skin="primary" title="零库存" value="0">

                    <div class="btns" style="top: -5px;position: relative;float: right;margin-top: 0;margin-left: 15px;">
                        <a class="ui-btn mrb ui-btn-sp" id="filter-submit">查询</a>
					</div>
                </li>

				<!-- <span class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5713" target="_blank" class="video-icon" style="margin-right: 5px;"></a>功能简介</span> -->
			</ul>
		</div>

        <!-- 下拉树选择（商品类别） -->
	    {include file="admin@popup/goods_category"/}

	</div>

	

	<!-- no data -->
	<div class="no-query"></div>
	<!-- grid begin -->
	<div class="ui-print" id="ui-print" style="visibility: hidden;">
		<!-- 列配置 -->
		<div class="cf box-flex">
			<div class="flex">
				<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
			</div>

            <div class="fr">
				<a class="ui-btn-bill ui-btn-add mrb" id="add">保存盘点结果</a>
				<a class="ui-btn-bill ui-btn-add" id="save">生成盘点单据</a>
			</div>
		</div>

		<div class="grid-wrap" id="grid-wrap" style="padding-bottom: 30px;padding-right: 30px;">
			<table id="grid"></table>
			<div id="page"></div>
		</div>
	</div>
	<!-- grid end -->

	<!--  以隐藏的方式获取商品的样式 ，作用是赋值 -->
	<div style="display:none;">
		
	</div>
</div>

<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>



<script type="text/javascript">

	$(document).ready(function () {

		// 点击查询按钮
		$("#filter-submit").click(function () {
			$("#ui-print").css({ "visibility": "visible" });  //显示表格数据
			$(".no-query").hide();  //隐藏提示




			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: { 'ajax': '100'}, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
		});



		//alert("1111");
		$("#grid").jqGrid({
			url: '/store/inventorysn/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			colNames: ["id","仓库","商品类别", "商品编号", "商品名称","规格型号", "单位", "系统库存", "<span class='red'>*</span>实际库存", "盘点结果"],
			colModel: [
				{ name: 'id', width: 60 ,label: "id",hidden:true},
				{ name: 'store_name', width: 100, label: "仓库"},
				{ name: 'good_category_name', width: 100 ,label: "商品类别"},
				{ name: 'sn', width: 100 ,label: "商品编号"},
				{ name: 'good_name', width: 100 ,label: "商品名称"},
				{ name: 'model' ,width: 100 ,label: "规格型号"},
				{ name: 'unit_name' ,width: 50 ,label: "单位"},
				{ name: 'system_kc' ,width: 100 ,label: "系统库存"},
				{ name: 'user_kc' ,width: 100 ,label: "实际库存", align:"right", formatter: snTd},
				{ name: 'result' ,width: 120 ,label: "盘点结果",formatter:results}
				
			],
            cellEdit: true,
            cellurl: '/',
			sortable: true,  //排序
		
			rowNum: 100,
			rowList: [100, 200, 500],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置

			pgbuttons: true,//翻页按钮
            rownumbers: true, //自增序号
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			}
		});

		
	});

	var num=0;   //实际库存数量
	var systemNum=0;  //系统库存数量
	var sn_arr=[];  //盘点sn的数组
	var system_arr=[];  //盘点sn的数组
	var sns='';

	function snTd(cellvalue, options, rowObject) {
		//alert();
		systemNum=rowObject.system_kc;  //获取系统库存
		return '<div style="width:"100%;height:100%;" onclick="snFun('+ rowObject.store_id +','+ rowObject.good_id +')"><span class="qtyInsert" id="snBtn_'+ rowObject.store_id +'_'+ rowObject.good_id +'">SN</span><span id="snNum_'+ rowObject.store_id +'_'+ rowObject.good_id +'"></span></div>';
	}

	function results(cellvalue, options, rowObject){
		return '<div id="resultsTd"></div>';
	}

	
	function snFun(store_id,good_id){
		var _this=this;
	
		//return false;
		layer.open({
			type: 2,
			title: "实际库存序列号",
			shadeClose: true,
			shade: 0.3,
			maxmin: false, //开启最大化最小化按钮
			area: ['620px', '560px'],
			fixed: false, //不固定
			btn: ['确定', '取消'],
			content: "/store/inventorysn/sernumlist.html?store_id="+store_id+"&good_id="+good_id,
			btn1: function (index, layero) {
				var body = layer.getChildFrame('body', index);
				sns=body.find("#snCon").val(); //实际库存sn
				systemSns=body.find("#systemSnCon").val(); //系统库存sn

				var arr = sns.split('\n');
				systemSns=systemSns.split('\n');
				system_arr=[];
				sn_arr=[];

				for(var i in systemSns){
					if(systemSns[i]==""){
						
					}else{
						system_arr.push(systemSns[i]);
					}
				}
				for(var i in arr){
					if(arr[i]==""){
						
					}else{
						sn_arr.push(arr[i]);
					}
				}
				//console.log(sn_arr.length);

				 num =sn_arr.length;
				
				
				resultFun(store_id,good_id,sn_arr,system_arr);

				// layer.close(index);
				return false;
			},
			btn2: function (index, layero) {
				layer.close(index);
				return false;
			}
		})
	}


	function resultFun(store_id,good_id,sns,systemSns){
		layer.open({
			type: 2,
			title: "盘点结果",
			shadeClose: true,
			shade: 0.3,
			maxmin: false, //开启最大化最小化按钮
			area: ['420px', '580px'],
			fixed: false, //不固定
			btn: ['确定', '取消'],
			content: "/store/inventorysn/sninventoryresult.html?store_id="+store_id+"&good_id="+good_id+"&sns="+sns+"&systemSns="+systemSns,
			btn1: function (index, layero) {
				// console.log("盘点结果");
				var body = layer.getChildFrame('body', index);

				var rightNum=body.find("#rightNum").val(); //匹配序列号
				var addNum=body.find("#addNum").val(); //盘盈序列号
				var delNum=body.find("#delNum").val(); //盘亏序列号

				$("#snNum_"+store_id+"_"+good_id).html(parseFloat(num).toFixed(2));
				$("#snBtn_"+store_id+"_"+good_id).addClass("qtyInsertAfter").removeClass("qtyInsert");

				var resultHtml='<span style="color:#0070E1">匹配序列号:'+ rightNum +'个</span></br><span style="color:#0070E1">盘盈序列号:'+addNum+'个</span></br><span style="color:#0070E1">盘亏序列号:'+delNum+'个</span>';

				$("#resultsTd").html(resultHtml);


				layer.closeAll();
				return false;
			},
			btn2: function (index, layero) {
				layer.close(index);
				return false;
			}
		})
	}

	// function updades(){
	// 	console.log("AAA");
	// }
</script>

<script type="text/javascript">
	$(document).ready(function () {
      


        //顶部搜索是否展开（1：展开，0：未展开）
        var headH = 0;  
		$("#conditions-trigger").click(function () {
			if (headH == 0) {
				headH = 1;
				$("#filterItems").css({ "height": "auto" });
				$(this).html("&nbsp;收起条件<b class='act'></b>");
			} else {
				headH = 0;
				$("#filterItems").css({ "height": "44px" });
				// $("#filterItems").animate({height:'44px'});
				$(this).html("&nbsp;更多条件<b></b>");
			}
		});

        



    });

</script>

{include file="admin@public/footer"/}